<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <BasicTable @register="registerTable" :searchInfo="searchInfo">
      <template #toolbar>
        <!-- <a-button type="primary" @click="handleCreate">新增模板</a-button> -->
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                icon: 'clarity:note-edit-line',
                tooltip: '编辑模板',
                onClick: handleView.bind(null, record),
              },
              {
                icon: 'ant-design:signature-filled',
                tooltip: '发起签署',
                onClick: handleStartContract.bind(null, record),
              },
              {
                icon: 'ant-design:delete-outlined',
                color: 'error',
                tooltip: '删除此模板',
                popConfirm: {
                  title: '是否确认删除',
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { reactive } from 'vue';

  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { PageWrapper } from '@/components/Page';

  import { columns, searchFormSchema } from './template.data';
  import { useGo } from '@/hooks/web/usePage';
  import { getContractTemplateList } from '@/api/contract/template';

  defineOptions({ name: 'ContractTemplateList' });

  const go = useGo();
  const searchInfo = reactive<Recordable>({});
  const [registerTable] = useTable({
    title: '模板列表',
    api: getContractTemplateList,
    showIndexColumn: false,
    rowKey: 'id',
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    handleSearchInfoFn(info) {
      console.log('handleSearchInfoFn', info);
      return info;
    },
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      // slots: { customRender: 'action' },
    },
  });

  function handleDelete(record: Recordable) {
    console.log(record);
  }

  function handleCreate() {}

  function handleView(record: Recordable) {
    go({
      name: 'ContractTemplateView',
      params: { id: record.id },
    });
  }
  function handleStartContract(record: Recordable) {
    go({
      name: 'ContractConsoleView',
      query: { temId: record.id },
    });
  }
</script>
